/**
 * Created by zhangjinrui on 17/6/27.
 */

public class Solution376 {

    public static void main(String args[]) {
        Solution376 s = new Solution376();
        System.out.println(s.wiggleMaxLength(new int[]{1,2,2,2,3}));
    }

    public int wiggleMaxLength(int[] nums) {
        if (nums.length <= 1) {
            return nums.length;
        }
        int len = 1;
        for (int i = 1; i < nums.length; ) {
            int flag = 0;
            while (i < nums.length && nums[i] == nums[i - 1]) {
                i++;
            }
            while (i < nums.length && nums[i] - nums[i - 1] >= 0) {
                i++;
                flag = 1;
            }
            len += flag;
            flag = 0;
            while (i < nums.length && nums[i] - nums[i - 1] <= 0) {
                i++;
                flag = 1;
            }
            len += flag;
        }
//        len -= nums[1] - nums[0] == 0 ? 1 : 0;
        return len;
    }
}
